package cn.mdmm.socket;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.Socket;
import java.net.UnknownHostException;

public class ReceiveThread extends Thread {
	Socket socket;

	public ReceiveThread() {
		super();
	}

	public ReceiveThread(Socket socket) {
		super();
		this.socket = socket;
	}

	@Override
	public void run() {
		try {
			while (true) {
				// 由Socket对象得到输出流，并构造PrintWriter对象
				// 3、获取输入流，并读取服务器端的响应信息
				BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
				// 由Socket对象得到输入流，并构造相应的BufferedReader对象

				// 在系统标准输出上打印读入的字符串
				System.out.println("\nServer:" + in.readLine());
			}
		} catch (UnknownHostException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}
